package yicr;



/**
 * <h3>Title:</h3>
 * <p>
 *
 * <h3>Description</h3>
 * <p>
 *
 * <h3>Author</h3>
 * <p>
 * Lin Shao
 * <h3>Update Time</h3>
 *
 * @author Lin Shao
 * @version 1.0
 */
public class GisFunction {

    static public double distance(double longitude1,double latitude1,double longitude2,double latitude2){
        longitude1 = longitude1 * 3.14159265 / 180;
        longitude2 = longitude2 * 3.14159265 / 180;
        latitude1 = latitude1 * 3.14159265 / 180;
        latitude2 = latitude2 * 3.14159265 / 180;

        double temp1 = (Math.cos(longitude1) * Math.cos(longitude2) + Math.sin(longitude1) * Math.sin(longitude2) * Math.cos(latitude1 - latitude2)) - 0.000000000000001;
        double distance = 6369426.75 * Math.acos(temp1);

        return distance;
    }



    static public double cellsAngel(double longitude1,double latitude1,double longitude2,double latitude2){
        double hypotenuse=distance(longitude1,latitude1,longitude2,latitude2);
        double opposite=distance(longitude1,latitude1,longitude2,latitude1);
        double angel= Math.asin(opposite/hypotenuse)*180/ Math.PI;

        if(longitude2>longitude1){

            if(latitude2>latitude1){//0-90
                return angel;
            }else{
                return 180-angel;//90-180
            }
        }else{
            if(latitude2>latitude1){
                return 360-angel;//270-360
            }else{
                return 180+angel;//180-270
            }
        }
    }


    //经度或纬度  相差0.1，大概相差10km

    public void test1(){
        double longitude1=113.1111;
        double latitude1=34.2222;
        double longitude2=113.2111;
        double latitude2=34.2222;

        double distance1=distance(longitude1,latitude1,longitude2,latitude2);

        System.out.println(Math.asin(0.5)*180/ Math.PI);

        System.out.println(distance1);
        System.out.println(cellsAngel(longitude1, latitude1, longitude2, latitude2));
    }
}
